import { notification } from "antd";
import { NotificationConfig, NotificationInstance } from "antd/es/notification/interface";
import React, { createContext, useContext } from "react";

export namespace Notificatorio {
  const NOTIFICATORIO_CTX = createContext<NotificationInstance>(notification)
  export interface ProviderProps extends React.PropsWithChildren, NotificationConfig { }
  export function Provider(props: ProviderProps) {
    const { children, ...config_options } = props
    const [n , antd_ctx] = notification.useNotification(config_options);
    return (
      <>
        {antd_ctx}
        <NOTIFICATORIO_CTX.Provider value={n}>
          {children}
        </NOTIFICATORIO_CTX.Provider>
      </>
    )
  }

  export function use(): [NotificationInstance] {
    const n = useContext(NOTIFICATORIO_CTX)
    return [n]
  }
}